/*   1:    */ package org.jetbrains.lang.manifest.parser;
/*   2:    */ 
/*   3:    */

import com.intellij.lang.ASTNode;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiBuilder.Marker;
import com.intellij.lang.PsiBuilderUtil;
import com.intellij.lang.PsiParser;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.lang.manifest.ManifestBundle;
import org.jetbrains.lang.manifest.header.HeaderParser;
import org.jetbrains.lang.manifest.header.HeaderParserRepository;
import org.jetbrains.lang.manifest.header.impl.StandardHeaderParser;
import org.jetbrains.lang.manifest.psi.ManifestElementType;
import org.jetbrains.lang.manifest.psi.ManifestTokenType;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */ 
/*  23:    */ public class ManifestParser
/*  24:    */   implements PsiParser
/*  25:    */ {
/*  26: 50 */   public static final TokenSet HEADER_END_TOKENS = TokenSet.create(new IElementType[] { ManifestTokenType.SECTION_END, ManifestTokenType.HEADER_NAME });
/*  27:    */   private final HeaderParserRepository a;
/*  28:    */   
/*  29:    */   public ManifestParser()
/*  30:    */   {
/*  31: 55 */     this.a = ((HeaderParserRepository)ServiceManager.getService(HeaderParserRepository.class));
/*  32:    */   }
/*  33:    */   
/*  34:    */   @NotNull
/*  35:    */   public ASTNode parse(IElementType paramIElementType, PsiBuilder paramPsiBuilder)
/*  36:    */   {
/*  37: 61 */     paramPsiBuilder.setDebugMode(ApplicationManager.getApplication().isUnitTestMode());
/*  38:    */     
/*  39: 63 */     PsiBuilder.Marker localMarker = paramPsiBuilder.mark();
/*  40: 64 */     while (!paramPsiBuilder.eof()) {
/*  41: 65 */       a(paramPsiBuilder);
/*  42:    */     }
/*  43: 67 */     localMarker.done(paramIElementType); ASTNode 
/*  44:    */     
/*  45: 69 */       tmp51_46 = paramPsiBuilder.getTreeBuilt();
/*  46: 69 */     if (tmp51_46 == null) {
/*  47: 69 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/lang/manifest/parser/ManifestParser", "parse" }));
/*  48:    */     }
/*  49: 69 */     return tmp51_46;
/*  50:    */   }
/*  51:    */   
/*  52:    */   private void a(PsiBuilder paramPsiBuilder)
/*  53:    */   {
/*  54: 73 */     PsiBuilder.Marker localMarker1 = paramPsiBuilder.mark();
/*  55: 75 */     while (!paramPsiBuilder.eof())
/*  56:    */     {
/*  57: 76 */       IElementType localIElementType = paramPsiBuilder.getTokenType();
/*  58: 77 */       if (localIElementType == ManifestTokenType.HEADER_NAME)
/*  59:    */       {
/*  60: 78 */         b(paramPsiBuilder);
/*  61:    */       }
/*  62:    */       else
/*  63:    */       {
/*  64: 80 */         if (localIElementType == ManifestTokenType.SECTION_END)
/*  65:    */         {
/*  66: 81 */           paramPsiBuilder.advanceLexer();
/*  67: 82 */           break;
/*  68:    */         }
/*  69: 85 */         PsiBuilder.Marker localMarker2 = paramPsiBuilder.mark();
/*  70: 86 */         c(paramPsiBuilder);
/*  71: 87 */         localMarker2.error(ManifestBundle.message("manifest.header.expected", new Object[0]));
/*  72:    */       }
/*  73:    */     }
/*  74: 91 */     localMarker1.done(ManifestElementType.SECTION);
/*  75:    */   }
/*  76:    */   
/*  77:    */   private void b(PsiBuilder paramPsiBuilder)
/*  78:    */   {
/*  79: 95 */     PsiBuilder.Marker localMarker1 = paramPsiBuilder.mark();
/*  80: 96 */     String str = paramPsiBuilder.getTokenText();
/*  81: 97 */     assert (str != null) : ("[" + paramPsiBuilder.getOriginalText() + "]@" + paramPsiBuilder.getCurrentOffset());
/*  82: 98 */     paramPsiBuilder.advanceLexer();
/*  83:    */     
/*  84:100 */     PsiBuilder.Marker localMarker2 = null;
/*  85:101 */     if (paramPsiBuilder.getTokenType() == TokenType.BAD_CHARACTER)
/*  86:    */     {
/*  87:102 */       localMarker2 = paramPsiBuilder.mark();
/*  88:103 */       while (paramPsiBuilder.getTokenType() == TokenType.BAD_CHARACTER) {
/*  89:104 */         paramPsiBuilder.advanceLexer();
/*  90:    */       }
/*  91:106 */       localMarker2.error(ManifestBundle.message("manifest.unexpected.token", new Object[0]));
/*  92:    */     }
/*  93:    */     Object localObject;
/*  94:109 */     if (paramPsiBuilder.getTokenType() == ManifestTokenType.COLON)
/*  95:    */     {
/*  96:110 */       paramPsiBuilder.advanceLexer();
/*  97:112 */       if (!PsiBuilderUtil.expect(paramPsiBuilder, ManifestTokenType.SIGNIFICANT_SPACE)) {
/*  98:113 */         paramPsiBuilder.error(ManifestBundle.message("manifest.whitespace.expected", new Object[0]));
/*  99:    */       }
/* 100:116 */       localObject = (HeaderParser)ObjectUtils.notNull(this.a.getHeaderParser(str), StandardHeaderParser.INSTANCE);
/* 101:117 */       ((HeaderParser)localObject).parse(paramPsiBuilder);
/* 102:    */     }
/* 103:    */     else
/* 104:    */     {
/* 105:121 */       if (localMarker2 == null)
/* 106:    */       {
/* 107:122 */         localObject = paramPsiBuilder.mark();
/* 108:    */       }
/* 109:    */       else
/* 110:    */       {
/* 111:125 */         localObject = localMarker2.precede();
/* 112:126 */         localMarker2.drop();
/* 113:    */       }
/* 114:128 */       c(paramPsiBuilder);
/* 115:129 */       ((PsiBuilder.Marker)localObject).error(ManifestBundle.message("manifest.colon.expected", new Object[0]));
/* 116:    */     }
/* 117:132 */     localMarker1.done(ManifestElementType.HEADER);
/* 118:    */   }
/* 119:    */   
/* 120:    */   private static void c(PsiBuilder paramPsiBuilder)
/* 121:    */   {
/* 122:136 */     while ((!paramPsiBuilder.eof()) && (!HEADER_END_TOKENS.contains(paramPsiBuilder.getTokenType()))) {
/* 123:137 */       paramPsiBuilder.advanceLexer();
/* 124:    */     }
/* 125:    */   }
/* 126:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.lang.manifest.parser.ManifestParser

 * JD-Core Version:    0.7.0.1

 */